﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;
using System.IO;
namespace WlanDesign
{
    public partial class FormNetSet : Form
    {
        public FormNetSet()
        {
            InitializeComponent();
        }

        public static bool IsUrl(string _value)
        {
            Regex regex = new Regex(@"(((ht|f)tp(s?):\/\/)|(www\.[^ \[\]\(\)\n\r\t]+)|(([012]?[0-9]{1,2}\.){3}[012]?[0-9]{1,2})\/)([^ \[\]\(\),;&quot;'&lt;&gt;\n\r\t]+)([^\. \[\]\(\),;&quot;'&lt;&gt;\n\r\t])|(([012]?[0-9]{1,2}\.){3}[012]?[0-9]{1,2})", RegexOptions.IgnoreCase);
            return regex.Match(_value).Success;
        }

        private void FormNetSet_Load(object sender, EventArgs e)
        {

        }

        private void FormNetSet_FormClosing(object sender, FormClosingEventArgs e)
        {
            FormStartup.formNetSetstatus = true;
        }

        private void btnNetSav_Click(object sender, EventArgs e)
        {
            string serUrl = txtSevAdr.Text;
            bool isUrl = IsUrl(serUrl);
            if (isUrl == true)
            {
                if (!Directory.Exists(@FormStartup.IniFile))
                {
                    Directory.CreateDirectory(FormStartup.IniFile);
                    FileStream fs = new FileStream(FormStartup.IniFileName, FileMode.CreateNew);
                    fs.Close();
                }
                FormStartup.WriteIniTxt(FormStartup.IniFileName, "network", "svrurl", serUrl);
                MessageBox.Show("网络设置成功！");
                this.Close();
            }
            else
            {
                MessageBox.Show("您输入的服务器地址不符合Url规范，请重新输入！");
                txtSevAdr.Text = "";
            }
        }

        private void btnNetCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
